
from typing import Union
import httpx
from localJenkins.local_jenkins import JenkinsContest

class Send_DingTalk(JenkinsContest):

    def __init__(self):
        super().__init__()
        self.webhook = "https://oapi.dingtalk.com/robot/send?access_token=566a885b479ac506a130fe89a2fd1a0f6b40be7764062b9935ff9c9e9635be87"

    def push_message(self, content: str) -> Union[httpx.Response, str]:
        headers = {'Content-Type': 'application/json'}

        content = {
            "msgtype": "actionCard",
            "actionCard": {
                "title": "测试报告",
                "text": content,
                "btnOrientation": "1",
                "btns": [
                    {"title": "查看详情",
                     "actionURL": self.report_url}
                ]
            },
            "at": {
                # "atMobiles": mobile_list,
                "isAtAll": True
            }
        }

        response = httpx.post(url=self.webhook, json=content, verify=False)

        if response.json()['errmsg'] != "ok":
            return response.text

        return response


















